﻿Chenxin.UI.BlackListMgr=Chenxin.extend(Chenxin.UI.PageCommon,{
    autoInitForm:false,
    actionUrl:'service/blackListManage.ashx',
    createSearch:function(){
		return new Chenxin.UI.BlackListMgrSearch({
			scope:this,
			afterGetParamJson:function(data){

			    if($("#hidConditionCont").val() != ""){
			        data.CondType = $("#hidConditionType").val();
			        data.CondCont = $("#hidConditionCont").val();
			    }
                if( data.divLevelSel ){
                    data.Level = data.divLevelSel;
                    delete data.divLevelSel;
                }
            }
		});
	},
	createGrid:function(){
		return new Chenxin.UI.Pagination({
	        type:"post",
			actionUrl:this.actionUrl + "?op=Search",
			id:'houseList',
			renderTo: 'house_table'
		});
	},
	createForm:function(){
        return new Chenxin.UI.BlackListMgrForm({
            scope:this,
            afterGetFormJson:function(json){
                json.Level=json.divLevel;
                delete json.divLevel;  
            }
        });
	},
	initEvent:function(){
	    var _this=this;
	    
        /******************事件：添加黑名单按钮******************/
        $('#aAddBlackList').live('click',function(){
        
            _this.form.reset();
            _this.form.show();
            _this.form.setTitle('添加黑名单');
            
        });
        /******************事件：编辑黑名单按钮******************/
        $('.clsEditBlackList').live('click',function(){
        
            var strRecordId = $(this).parent("h1:first").children("input[name='hidRecordId']").val();
            
            Chenxin.ajax({
				type: "post",
				dataType: "json",
				url: _this.actionUrl,
				data: {op:"GetSingle",RecordId:strRecordId},
				onSuccess: function(data) {
                    //类别div赋值
				    data.divLevel=data.Level;

				    _this.form.currentModel=data;
				    _this.form.fitData(data);
                    _this.form.show();
                    _this.form.setTitle('编辑黑名单');
                }
            });
            
        });
        /******************事件：删除黑名单按钮******************/
	    $(".clsDelBlackList").live("click",function(){
	        //记录ID
	        var strRecordId = $(this).parent("h1:first").children("input[name='hidRecordId']").val();
	        //删除确定
	        if(!confirm("确定要删除吗？")){
	            return false;
	        }
    	    
    	    Chenxin.ajax({
				type: "post",
				dataType: "json",
				url: _this.actionUrl,
				data: {op:"Del",RecordId:strRecordId},
				onSuccess: function(data,msg) {
                    alert(msg);
                    _this.reloadGrid();
                }
            });
	    });
	    
	    /******************事件：单个字母选择******************/
	    $("a[name='aLetter']").click(function(){
	        var param = _this.search.getParamJson();
	        param.Initial = $(this).children("span").text();
	        _this.grid.reload(param,true);
	    });
    	
	    /******************事件：字母按钮事件******************/
	    $("a[name='aAllLetter']").click(function(){
	        _this.reloadGrid();
	    });
                
    },
	initComponent:function(){
		Chenxin.UI.BlackListMgr.superclass.initComponent.call(this);
	}
});

/**
*查询面板
*/
Chenxin.UI.BlackListMgrSearch=Chenxin.extend(Chenxin.UI.SearchCommon,{
    id:'blacklist_search',
	initEvent:function(){
		var _this=this;
        
		/******************事件：查询事件******************/
		$('#btSreachBlackList').click(function(){
		    _this.scope.reloadGrid();
		});
		
		/******************事件：失去焦点******************/
        $("#txtCondition").blur(function(){
            _this.setSearchMatch();
        });
        
        /******************事件：匹配选择******************/
        $("#dlSearchMatch").live("click", function(event) {
            
            if (event.target.tagName == "A") {
                var objParent = $(event.target).parent();
                $("#txtCondition").val($(objParent).find("input[name='hidCont']").val());
                $("#hidConditionCont").val($(objParent).find("input[name='hidCont']").val());
            }
        });

        /******************事件：条件输入框匹配******************/
        $("#txtCondition").keyup(function(){
            if ($("#txtCondition").val() == "") {
                $("#hidConditionCont").val("");
                $("#dlSearchMatch").hide();
                return false;
            }

            Chenxin.ajax({
		        type: "post",
		        dataType: "json",
		        url: 'service/blackListManage.ashx',
			    data: {op:"GetCondition",Query:$("#txtCondition").val()},
		        onSuccess: function(data) {
                    $("#dlSearchMatch").html(data);
                    $("#dlSearchMatch").show();
		        }
	        });
	        
        });
        
	},
	createComboList:function(){
	    var cmbLevelSel = new Chenxin.UI.Combo({
			containerId: '#divLevelSel',
			tbxWidth:45,
			items:comboCommon.blackListLevel
		});
		return [cmbLevelSel];
	},
	setSearchMatch:function(){
	    var _this=this;
	    _this.intervalId = window.setInterval(function() { $("#dlSearchMatch").hide(); _this.clearTime() ; }, 300);
	},
	clearTime:function(){
	    window.clearInterval(this.intervalId);
	}
});

/**
*添加黑名单
*/
Chenxin.UI.BlackListMgrForm=Chenxin.extend(Chenxin.UI.FormCommon,{	
	actionUrl:'service/blackListManage.ashx',
	id:'jqmAddBlackList',
	renderTo:'divAddBlackList',
	winCls:'',
	jqmWidth:500,
	createComboList:function(){
	    var cmbLevel = new Chenxin.UI.Combo({
			containerId: '#divLevel',
			tbxWidth:45,
			items:comboCommon.blackListLevel
		});
		return [cmbLevel];
	},
	initFormValidator:function(){
	    var _this=this;
	    
	    //主题验证
	    $("#TitleEditAllTask").formValidator({ validatorgroup:this.id,
            onshow: "请输入主题", onfocus: "请输入主题", oncorrect: "OK"
        }).inputValidator({
            min: 1, empty: { leftempty: false, rightempty: false, emptyerror: "主题不能为空!" }, onerror: "主题不能为空!"
	    });
	    //用户名
        $("#UserName").formValidator({ validatorgroup:this.id,
            onshow:"请输入用户名！",
            onfocus:"请输入用户名",
            oncorrect:"OK"
        }).inputValidator({
            min: 1, 
            empty: { leftempty: false, rightempty: false, emptyerror: "用户名不能为空!" }, 
            onerror: "用户名不能为空!"
        });

        //电话
        $("#Tel").formValidator({ 
            validatorgroup: this.id,
            onshow: "请输入电话！", 
            onfocus: "请输入电话", 
            oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                if ($("#Tel").val() == "" && $("#Mobile").val() == "") {
                    return false;
                } else {
                    return true;
                }
            }, onerror: "请输入手机号码或电话！"
        });
        //手机号码
        $("#Mobile").formValidator({ 
            validatorgroup: this.id,
            onshow: "请输入手机号！", 
            onfocus: "请输入手机号", 
            oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) { if (val == "") return true; return val.isMobile(); }, onerror: "请输入正确的手机号"
        }).functionValidator({
            fun: function(val, elem) {
                if ($("#Tel").val() == "" && $("#Mobile").val() == "") {
                    return false;
                } else {
                    return true;
                }
            }, onerror: "请输入手机号码或电话！"
        });
        //Email
        $("#Email").formValidator({ validatorgroup:this.id,
            onshow:"可以为空",
            onfocus:"可以为空",
            oncorrect:"OK"
        }).regexValidator({
            regexp:"emailOrNull",
            datatype:"enum",
            onerror:"输入的Email格式不正确"
        });
        
	},
	createForm:function(){
		return formCommon.BlackListMgrForm('EditBlackList');
	},
	initEvent:function(){

	    var _this=this;
	    /******************事件：提交事件******************/
		$('#btSubmitEditBlackList').click(function(){
		
	        _this.op = "Save";
            _this.save();   
		});
		
		/******************事件：关闭事件******************/
		$('#btCloseEditBlackList').click(function(){
			_this.hide();
		});	
		
	},
    saveSucc:function(){
	    this.reloadGrid();
    },
	initComponent:function(){
		Chenxin.UI.BlackListMgrForm.superclass.initComponent.call(this);
	}
});
                 	
$(document).ready(function(){
    var _this=this;
    this.BlackListMgr=new Chenxin.UI.BlackListMgr();
});